//package com.yunhe.device.controller.device;
//
//import com.yunhe.common.model.PageParam;
//import com.yunhe.common.model.authority.ResourceTree;
//import com.yunhe.device.domain.device.EnergyUnit;
//import com.yunhe.common.exception.ArgumentErrorException;
//import com.yunhe.common.exception.ObjectNotFoundException;
//import com.yunhe.common.exception.UniqueConstraintsException;
//import com.yunhe.common.model.ResultObject;
//import com.yunhe.device.service.device.EnergyUnitService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.format.annotation.DateTimeFormat;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Date;
//import java.util.List;
//import java.util.Optional;
//
///**
// * 能量单元controller
// * @author liuronglei
// */
//@Api(value = "energyUnit", description = "能量单元维护", tags = {"Model_EnergyUnit"})
//@RestController
//@RequestMapping("/energyUnits")
//public class EnergyUnitController {
//
//    @Autowired
//    private EnergyUnitService energyUnitService;
//
//    @ApiOperation("新增能量单元")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "stationCode", value = "电站代码", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(method = RequestMethod.POST)
//    public ResponseEntity<ResultObject> post(
//            @RequestParam("firmId") Long firmId,
//            @RequestParam("stationId") Long stationId,
//            @RequestBody EnergyUnit energyUnit)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        EnergyUnit result = energyUnitService.createEnergyUnit(firmId, stationId, energyUnit);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("删除能量单元")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "能量单元ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> delete(
//            @PathVariable("id") Long id) {
//        energyUnitService.deleteById(id);
//        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
//    }
//
//    @ApiOperation("更新能量单元(全部字段)")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path"),
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
//    public ResponseEntity<ResultObject> update(
//            @PathVariable("id") Long id,
//            @RequestBody EnergyUnit energyUnit)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        energyUnit.setId(id);
//        EnergyUnit result = energyUnitService.updateEnergyUnit(energyUnit);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("更新能量单元")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "code", value = "代码", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "name", value = "名称", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "title", value = "标题", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "capacity", value = "容量", dataType = "double", paramType = "query")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
//    public ResponseEntity<ResultObject> update(
//            @PathVariable("id") Long id,
//            @RequestParam("code") Optional<Long> code,
//            @RequestParam("name") Optional<String> name,
//            @RequestParam("title") Optional<String> title,
//            @RequestParam("capacity") Optional<Double> capacity,
//            @RequestParam("productionTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Optional<Date> productionTime)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        EnergyUnit result = energyUnitService.updateEnergyUnit(id, code.orElse(null), name.orElse(null),
//                title.orElse(null), capacity.orElse(null), productionTime.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据条件查找能量单元")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "stationCode", value = "电站代码", dataType = "long", paramType = "query")
//    })
//    @RequestMapping(method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> search(
//            @RequestParam("stationCode") Optional<Long> stationCode,
//            @RequestParam("stationId") Optional<Long> stationId,
//            @ModelAttribute PageParam pageParam) {
//        Iterable<EnergyUnit> results = energyUnitService.search(stationId.orElse(null), stationCode.orElse(null), pageParam);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    @ApiOperation("能量单元绑定设备")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "deviceIds", value = "设备ID列表", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/{id}/devices", method = RequestMethod.PUT)
//    public ResponseEntity<ResultObject> bindDevices(
//            @PathVariable("id") Long id,
//            @RequestParam("deviceIds") List<Long> deviceIds) {
//        energyUnitService.bindDevices(id, deviceIds);
//        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
//    }
//
//    @ApiOperation("能量单元解绑设备")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "deviceIds", value = "设备ID列表", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/{id}/devices", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> unbindDevices(
//            @PathVariable("id") Long id,
//            @RequestParam("deviceIds") List<Long> deviceIds) {
//        energyUnitService.unbindDevices(id, deviceIds);
//        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据能量单元和设备类型查询绑定设备")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "type", value = "设备类型", dataType = "string", paramType = "query")
//    })
//    @RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> searchDevices(
//            @PathVariable("id") Long id,
//            @RequestParam("type") Optional<String> type) {
//        Iterable<ResourceTree> result = energyUnitService.searchDevices(id, type.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 根据代码获得能量单元
//     * @param code 代码
//     */
//    @ApiOperation("根据代码获得能量单元")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "代码", required = true, dataType = "Long", paramType = "path")
//    })
//    @RequestMapping(value = "/byCode/{code}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getByCode(
//            @PathVariable("code") Long code) {
//        EnergyUnit energyUnit = energyUnitService.findByCode(code);
//        return new ResponseEntity<>(new ResultObject<>(energyUnit), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据ID查找能量单元")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findById(
//            @PathVariable("id") Long id) {
//        EnergyUnit result = energyUnitService.findById(id);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//}
